<?php
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST["submit"])){
    exit("错误执行");
}//检测是否有submit操作
 
include('conn.php');//链接数据库
 
$name = $_POST['name'];//post获得用户名表单值
$pwd = sha1($_POST['password']);//post获得用户密码单值
 
if ($name && $pwd){//如果用户名和密码都不为空
    $sql = "select * from user where username = '$name' and password='$pwd'";//检测数据库是否有对应的username和password的sql
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    if($stmt->fetch(PDO::FETCH_BOUND)){//0 false 1 true
        header("refresh:0;url=http://localhost/ic/goods/goods.html");//如果成功跳转至welcome.html页面
        exit;
    }else{
        echo "用户名或密码错误";
        echo "<script>
    setTimeout(function(){window.location.href='signup.html';},1000);
            </script>";//如果错误使用js 1秒后跳转到登录页面重试;
    }
 
 
}else{//如果用户名或密码有空
    echo "请输入完整的账号或密码";
    echo "
      <script>
           setTimeout(function(){window.location.href='signup.html';},1000);
     </script>";
 
    //如果错误使用js 1秒后跳转到登录页面重试;
}
 
$pdo = null;
?>